﻿using Coldairarrow.Business.View;
using Coldairarrow.Entity.View;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.View
{
    [Route("/View/[controller]/[action]")]
    public class View_Base_DepartmentController : BaseApiController
    {
        #region DI

        public View_Base_DepartmentController(IView_Base_DepartmentBusiness view_Base_DepartmentBus)
        {
            _view_Base_DepartmentBus = view_Base_DepartmentBus;
        }

        IView_Base_DepartmentBusiness _view_Base_DepartmentBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<List<ViewBase_DepartmentTreeDTO>> GetTreeDataLists(ViewDepartmentsTreeInputDTO input)
        {
            return await _view_Base_DepartmentBus.GetTreeDataListAsync(input);
        }

        [HttpPost]
        public async Task<List<ViewBase_DepartmentTreeDTO>> GetTreeTypeDataLists(ViewDepartmentsTreeInputDTO input)
        {
            return await _view_Base_DepartmentBus.GetTreeTypeDataListAsyncs(input);
        }
        [HttpPost]
        public async Task<List<ViewBase_DepartmentTreeDTO>> GetTreeTypeDataListBumenid(ViewDepartmentsTreeInputDTO input)
        {
            return await _view_Base_DepartmentBus.GetTreeTypeDataListBumen(input);
        }
        ///登录人所属组织
        [HttpPost]
        public async Task<List<Deptitemdto>> GetTreeDataListLog(ViewDepartmentsTreeInputDTO input) {
            return await _view_Base_DepartmentBus.GetItemDeptid(input);
        }
        ///根据法人找下级车间
        [HttpPost]
        public async Task<List<Deptitemdto>> GetItemDeptidvalueid(ViewDepartmentsTreeInputDTO input)
        {
            return await _view_Base_DepartmentBus.GetItemDeptidvalueid(input);
        }
        ///根据当前登陆人部门找下级车间
        [HttpPost]
        public async Task<List<Deptitemdto>> GetItemDeptidWorkShop(ViewDepartmentsTreeInputDTO input)
        {
            return await _view_Base_DepartmentBus.GetItemDeptidWorkShop(input);
        }
        [HttpPost]
        public async Task<View_Base_Department> GetTheData(IdInputDTO input)
        {
            return await _view_Base_DepartmentBus.GetTheDataAsync(input.id);
        }

        /// <summary>
        /// 根据仓库车间查找上级第一条法人 type=1
        /// </summary>
        /// <param name="deptid"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<View_Base_Department> GetDeptData(string deptid)
        {
            return await _view_Base_DepartmentBus.GetDeptDataAsync(deptid);
        }

        /// <summary>
        /// 获取登录人工厂下的所有部门信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<ViewBase_DepartmentTreeDTO>> GetDeptList()
        {
            return await _view_Base_DepartmentBus.GetDeptListAsync();
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(View_Base_Department data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _view_Base_DepartmentBus.AddDataAsync(data);
            }
            else
            {
                await _view_Base_DepartmentBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _view_Base_DepartmentBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}